const CONFIG_ARM64_VA_BITS: usize = 48;
const CONFIG_ARM64_PA_BITS: usize = 48;
const CONFIG_ARM64_PAGE_SHIFT: usize = 12;
const CONFIG_PGTABLE_LEVELS: usize = 4;

pub const VA_BITS: usize = CONFIG_ARM64_VA_BITS;
pub const PA_BITS: usize = CONFIG_ARM64_PA_BITS;

const fn arm64_hw_pgtable_levels_shift(level: usize) -> usize {
    (PAGE_SHIFT - 3) * (4 - (level)) + 3
}

// 12
pub const PAGE_SHIFT: usize = CONFIG_ARM64_PAGE_SHIFT;
// 0x1000
pub const PAGE_SIZE: usize = 1 << CONFIG_ARM64_PAGE_SHIFT;
// 0x...fff000
pub const PAGE_MASK: usize = !(PAGE_SIZE - 1);
// 512
pub const PTRS_PER_PTE: usize = 1 << (PAGE_SHIFT - 3);

// 21
pub const PMD_SHIFT: usize = arm64_hw_pgtable_levels_shift(2);
// 0x200000
pub const PMD_SIZE: usize = 1 << PMD_SHIFT;
// 0x...ffe00000
pub const PMD_MASK: usize = !(PMD_SIZE - 1);
// 512
pub const PTRS_PER_PMD: usize = 1 << (PAGE_SHIFT - 3);

// 30
pub const PUD_SHIFT: usize = arm64_hw_pgtable_levels_shift(1);
// 0x40000000
pub const PUD_SIZE: usize = 1 << PUD_SHIFT;
// 0x...ffc0000000
pub const PUD_MASK: usize = !(PUD_SIZE - 1);
// 512
pub const PTRS_PER_PUD: usize = 1 << (PAGE_SHIFT - 3);

// 39
pub const PGDIR_SHIFT: usize = arm64_hw_pgtable_levels_shift(4 - CONFIG_PGTABLE_LEVELS);
// 0x8000000000
pub const PGDIR_SIZE: usize = 1 << PGDIR_SHIFT;
// 0x...ff8000000000
pub const PGDIR_MASK: usize = !(PGDIR_SIZE - 1);
// 512
pub const PTRS_PER_PGD: usize = 1 << (VA_BITS - PGDIR_SHIFT);
